<?php

namespace App\Models\Edu;

use Illuminate\Database\Eloquent\Model;

class Term extends Model
{
	protected $table = 'edu_terms';

    protected $guarded = array();

    protected $with = ['type','branch'];

    public function categories()
    {
        return $this->hasMany('\App\Models\Edu\Category');
    }


    public function clases()
    {
        return $this->hasMany('\App\Models\Edu\Clase');//->orderBy('users_count','desc');
    }


    public function users()
    {
        return $this->hasMany('\App\Models\Edu\Tuser');
    }


    public function branch()
    {
        return $this->belongsTo('\App\Models\Mgt\Branch');
    }


    public function type()
    {
        return $this->belongsTo('\App\Models\Edu\Type');
    }

    /**
     * @return 录取成功
     */
    public function admits()
    {
        return $this->hasMany('\App\Models\Edu\Tuser')->where('status',2);
    }


    /**
     * 公益培训类型
     * @param  [type] $query [description]
     * @param  [type] $type  [description]
     * @return [type]        [description]
     */
    public function scopeTraining($query)
    {
        return $query->whereIn('type_id', [1,2]);
    }
}